package com.kmxd.ams.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kmxd.ams.client.system.IConfI18nSvc;
import com.kmxd.ams.client.system.dto.ConfI18nAddDTO;
import com.kmxd.ams.client.system.dto.ConfI18nEditDTO;
import com.kmxd.ams.client.system.dto.ConfI18nQueryDTO;
import com.kmxd.ams.client.system.vo.ConfI18nListVO;
import com.kmxd.ams.client.system.vo.ConfI18nVO;
import com.kmxd.ams.core.common.enums.LogLevelEnum;
import com.kmxd.ams.core.common.enums.LogTypeEnum;
import com.kmxd.ams.core.log.annotation.AutoLog;
import com.kmxd.ams.core.result.R;
import com.kmxd.ams.core.util.SecurityUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import java.util.Map;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 国际化语言配置 前端控制器
 *
 * @author ZuoLG
 * @since 2022-07-14
 */
@RestController
@Tag(name = "国际化语言配置")
@RequestMapping("/confI18n")
@AllArgsConstructor
public class ConfI18nCtl {

  private IConfI18nSvc confI18nService;

  /** 分页查询 */
  @Operation(summary = "分页查询")
  @GetMapping("/selectPage")
  @AutoLog(module = "国际化语言配置", type = LogTypeEnum.SYSTEM, level = LogLevelEnum.LOW, title = "分页查询")
  public R<Page<ConfI18nListVO>> selectPage(Page reqPage, ConfI18nQueryDTO req) {
    return R.success(confI18nService.selectPage(reqPage, req));
  }

  /** 新增 */
  @Operation(summary = "新增")
  @PostMapping("/add")
  @SaCheckPermission("system:confI18n:add")
  @AutoLog(module = "国际化语言配置", type = LogTypeEnum.SYSTEM, level = LogLevelEnum.LOW, title = "新增")
  public R<Void> add(@Validated @RequestBody ConfI18nAddDTO req) {
    confI18nService.add(req);
    return R.success();
  }

  /** 修改 */
  @Operation(summary = "修改")
  @PostMapping("/edit")
  @SaCheckPermission("system:confI18n:edit")
  @AutoLog(module = "国际化语言配置", type = LogTypeEnum.SYSTEM, level = LogLevelEnum.HIGH, title = "修改")
  public R<Void> edit(@Validated @RequestBody ConfI18nEditDTO req) {
    confI18nService.edit(req);
    return R.success();
  }

  /** 删除 */
  @Operation(summary = "删除")
  @PostMapping("/remove")
  @SaCheckPermission("system:confI18n:remove")
  @AutoLog(
      module = "国际化语言配置",
      type = LogTypeEnum.SYSTEM,
      level = LogLevelEnum.HIGH,
      title = "删除")
  public R<Void> remove(@RequestParam String ids) {
    confI18nService.remove(ids);
    return R.success();
  }

  /** 查看 */
  @Operation(summary = "查看")
  @GetMapping("/view")
  @AutoLog(module = "国际化语言配置", type = LogTypeEnum.SYSTEM, level = LogLevelEnum.LOW, title = "查看")
  public R<ConfI18nVO> view(@RequestParam Long id) {
    return R.success(confI18nService.view(id));
  }

  /** 查询部门树 */
  @Operation(summary = "多语言树列表")
  @GetMapping("/tree")
  @AutoLog(module = "部门管理", type = LogTypeEnum.SYSTEM, level = LogLevelEnum.LOW, title = "查询部门树")
  public R<List<Tree<String>>> tree() {
    return R.success(confI18nService.tree());
  }

  /** 分页查询 */
  @Operation(summary = "用户多语言信息")
  @GetMapping("/userI18nList")
  public R<Map<String, Map<String, String>>> userI18nList() {
    return R.success(confI18nService.getUserI18nList(SecurityUtil.getLangCode()));
  }
}
